package com.mg.case2;

import com.mg.case1.Person;
import org.junit.jupiter.api.Test;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

public class Main2 {

    @Test
    public void testHashMap() {
        Apple a1 = new Apple("Blue");
        Apple a2 = new Apple("Green");

        Map<Apple, Integer> map = new HashMap<>();
        map.put(a1, 10);
        map.put(a2, 20);

        System.out.println(map.get(new Apple("Green")));
    }

    @Test
    public void testStringHashCode() {

        for (int i = 0; i <100; i++) {
            if (31 * i == (i << 5) - i) {
                System.out.println(i + " = " + (i << 5));
            }
        }
    }

    @Test
    public void testStringEquals() {
        // 只有str3==str5==str6

        String str1 = "str";
        String str2 = "ing";
        String str3 = "str" + "ing";
        String str4 = str1 + str2;

        //false
        System.out.println(str3 == str4);

        String str5 = "string";
        //true
        System.out.println(str3 == str5);

        //false
        System.out.println(str4 == str5);

        String str6 = "str" + "in" + "g";
        // true
        System.out.println(str3 == str6);



        String str7 = new String("str");
        String str8 =  new String("ing");
        String str9 = str7 + str8;
        String str10 = str7 + str8;
        //false
        System.out.println(str3 == str9);
        //false
        System.out.println(str4 == str9);
        //false
        System.out.println(str5 == str9);
        //false
        System.out.println(str9 == str10);


        String str11 = str1 + str8;
        //false
        System.out.println(str3 == str11);
        //false
        System.out.println(str4 == str11);

    }
}